An excavator, one of work machines, includes a traveling body, an upper swing body capable of swinging on the traveling body, and work equipment, above the upper swing body. The work equipment includes a boom having one end pivotably supported on a base body, an arm having one end pivotably supported at the other end of the boom, and an attachment pivotably supported at the other end of the arm. The boom, the arm, and the attachment are driven by hydraulic cylinders. A stroke of the hydraulic cylinder is measured to detect the position/posture of this work equipment.
For example, Patent Literature 1 discloses an excavator including a position sensor which detects, by rotation of a rotary roller on a cylinder rod, a piston stroke position of the hydraulic cylinder which drives the work equipment. Since minute slippage occurs between this rotary roller and the cylinder rod, an error may be generated between an actual stroke position and the stroke position obtained from a detection result of the position sensor. Therefore, a magnetic force sensor is provided, as a reset sensor, at a reference position on an outer surface of a cylinder tube of the hydraulic cylinder in order to calibrate the stroke position obtained from the detection result of the position sensor at the reference position. The stroke position detected by the position sensor is calibrated every time the piston passes the reference position while operating, thereby achieving accurate position measurement.